package com.ruoyi.project.video.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * videoController
 * 
 * @author gzy
 * @date 2023-03-10
 */
@Controller
@RequestMapping("/video/video")
public class VideoInfoController extends BaseController
{
    private String prefix = "video/video";

    @Autowired
    private IVideoInfoService videoInfoService;

    @RequiresPermissions("video:video:view")
    @GetMapping()
    public String video()
    {
        return prefix + "/video";
    }

    /**
     * 查询video列表
     */
    @RequiresPermissions("video:video:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VideoInfo videoInfo)
    {
        startPage();
        List<VideoInfo> list = videoInfoService.selectVideoInfoList(videoInfo);
        return getDataTable(list);
    }

    /**
     * 导出video列表
     */
    @RequiresPermissions("video:video:export")
    @Log(title = "video", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VideoInfo videoInfo)
    {
        List<VideoInfo> list = videoInfoService.selectVideoInfoList(videoInfo);
        ExcelUtil<VideoInfo> util = new ExcelUtil<VideoInfo>(VideoInfo.class);
        return util.exportExcel(list, "video数据");
    }

    /**
     * 新增video
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存video
     */
    @RequiresPermissions("video:video:add")
    @Log(title = "video", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VideoInfo videoInfo)
    {
        return toAjax(videoInfoService.insertVideoInfo(videoInfo));
    }

    /**
     * 修改video
     */
    @RequiresPermissions("video:video:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        VideoInfo videoInfo = videoInfoService.selectVideoInfoById(id);
        mmap.put("videoInfo", videoInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存video
     */
    @RequiresPermissions("video:video:edit")
    @Log(title = "video", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VideoInfo videoInfo)
    {
        return toAjax(videoInfoService.updateVideoInfo(videoInfo));
    }

    /**
     * 删除video
     */
    @RequiresPermissions("video:video:remove")
    @Log(title = "video", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(videoInfoService.deleteVideoInfoByIds(ids));
    }
}
